package cn.madis.controller;

import cn.madis.domain.User;

import cn.madis.handler.UserBlockHandler;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class UserController {

    @Value("${test}")
    private Long test;

    @SentinelResource(value="user",blockHandler="getByIdBlockHandler",blockHandlerClass = UserBlockHandler.class
    ,fallback = "getByIdFallback")
    @GetMapping("/user/{id}")
    public User getById(@PathVariable Long id){
        return User.builder().id(test).name("test").intro("您好").build();
    }

    public User getByIdFallback(@PathVariable Long id,Throwable t){
        return User.builder().id(-2L).name("降级降级降级").intro("降级降级fall").build();
    }
}
